<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="spring" uri="http://www.springframework.org/tags"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%@ taglib prefix="sec" uri="http://www.springframework.org/security/tags"%>

<%@include file="/common/head.jsp" %>

<c:set var="module" value="productCategory"/>

<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
		<form action="${ctx }/admin/productCategory/save?id=${n.id }" id="detail-form" class="form-horizontal" method="post">
			<input type="hidden" name="parentCategory.id" id="pid"> 
			<input type="hidden" name="level" id="level" value="1"> 
			<div class="form-group">
                 <label class="col-sm-2 control-label">分类名称</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="name" value="${n.name }">
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">状态</label>
                 <div class="col-sm-10">
                 	<select name="status" class="form-control">
						<option value="">请选择状态</option>
						<c:forEach items="${pcss }" var="pcs">
							<option value="${pcs.value }"
								<c:if test="${pcs.value eq n.status }">selected="selected"</c:if>>${pcs.remark }</option>
						</c:forEach>
					</select>
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">编码</label>
                 <div class="col-sm-10">
                 	<input type="text" class="form-control" name="code" value="${n.code }">
                 </div>
             </div>	
             <div class="form-group">
                 <label class="col-sm-2 control-label">一级分类</label>
                 <div class="col-sm-10">
					<select  class="form-control" id="topCategory">
						<option value="">一级分类</option>
						<c:forEach items="${topCategories }" var="t">
						<option value="${t.id }" ${n.parentCategory.id eq t.id ? 'selected' : '' }>${t.name }</option>
						</c:forEach>
					</select>						                 	
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">二级分类</label>
                 <div class="col-sm-10">
                 	<select  class="form-control" id="subCategory">
                 		<%-- <c:if test="${not empty(n.city.id) }">
                 		<option value="${n.city.id }">${n.city.name }</option>
                 		</c:if> --%>
					</select>	
                 </div>
             </div>	
			<div class="form-group">
                 <label class="col-sm-2 control-label">分类图片</label>
                 <div class="col-sm-10">
                 	<input type="hidden" name="image" id="image" value="${n.image }" />
                 	<div class="my-images" single="true" images="${n.image }" id="image1" field="image">
                 	</div>
                 </div>
             </div>	
        	<div class="form-group">
                 <label class="col-sm-2 control-label"></label>
                 <div class="col-sm-10" style="text-align: center;">
					<input type="text" class=" btn btn-primary" value="保存" onclick="save()"/>
                 </div>
             </div>	
		</form>
</div>

<%@include file="/common/foot.jsp" %>
<script>
$(document).ready(function() {
	init_images('image1');
	
	$('#topCategory').change(function() {
		var categoryId = $(this).val();
		$('#pid').val(categoryId);
		$('#subCategory').html('');
		$('#level').val(2);
		if (categoryId != '') {
			$.ajax({
				url: "${ctx}/admin/productCategory/findCategory?id=" + categoryId,
				dataType: "json",
				success: function(array) {
					$('#subCategory').append('<option value="">二级分类</option>');
					for (var i = 0; i < array.length; i++) {
						var obj = array[i];
						var option = '<option value="' + obj.id + '">' + obj.name + '</option>';
						$('#subCategory').append(option);	
					}
				}
			});
		}
		
	});
	
	$('#subCategory').change(function() {
		var categoryId = $(this).val();
		if (categoryId!=null&&categoryId!='') {
			$('#pid').val(categoryId);
			$('#level').val(3);
		}
	});
});
function save() {
	$('#detail-form').ajaxSubmit({
		success: function(data) {
			if (isSuccess(data)) {
				 reload();
			} else {
			}
		}
	});
}
</script>
</body>
</html>
